<template lang="pug">
  VueUEditor(@ready='editorReady', :ueditorConfig='editorOptions', style='height: 500px')
</template>

<script>
import VueUEditor from 'vue-ueditor'
export default {
  components: {
    VueUEditor
  },
  model: {
    prop: 'defaultContent',
    event: 'change'
  },
  props: {
    defaultContent: {
      type: String,
      default: ''
    }
  },
  data () {
    return {
      /**
       * 使用服务器的lib，会加载服务器的config，忽略其他选项
       */
      path: window.APIBaseURL + '/modules/custom/ueditor/lib/',
      editorOptions: {
        allowDivTransToP: false,
    //         toolbars: [[
    //   'fullscreen', 'source', '|', 'undo', 'redo', '|',
    //   'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc', '|',
    //   'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',
    //   'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|',
    //   'directionalityltr', 'directionalityrtl', 'indent', '|',
    //   'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'touppercase', 'tolowercase', '|',
    //   'link', 'unlink', 'anchor', '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', '|',
    //   'simpleupload', 'insertimage', 'emotion', 'scrawl', 'insertvideo', 'music', 'attachment', 'map', 'gmap', 'insertframe', 'insertcode', 'webapp', 'pagebreak', 'template', 'background', '|',
    //   'horizontal', 'date', 'time', 'spechars', 'snapscreen', 'wordimage', '|',
    //   'inserttable', 'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow', 'insertcol', 'deletecol', 'mergecells', 'mergeright', 'mergedown', 'splittocells', 'splittorows', 'splittocols', 'charts', '|',
    //   'print', 'preview', 'searchreplace', 'drafts', 'help'
    // ]],

        toolbars: [[
          'fullscreen', 'source', '|',
          'forecolor', 'backcolor', 'bold', 'italic', 'underline', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'pasteplain', '|',
          'paragraph', 'fontfamily', 'fontsize', 'insertorderedlist', 'insertunorderedlist', '|',
          'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',
          'indent', 'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify',
          'link', 'unlink', 'anchor', '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', '|',
          '|', 'inserttable', 'insertimage', 'insertvideo', 'attachment'
        ]],
        iframeUrlMap: {
          'attachment': '/static/ueditor1_4_3_3/dialogs/attachment/attachment.html',
          'insertimage': '/static/ueditor1_4_3_3/dialogs/image/image.html',
          'insertvideo': '/static/ueditor1_4_3_3/dialogs/video/video.html'
        }
      }
    }
  },
  mounted () {

  },
  methods: {
    editorReady (instance) {
      // console.log('ueditor ready', instance)
      this.editor = instance
      instance.setContent(this.defaultContent)
      instance.addListener('contentChange', () => {
        this.$emit('change', this.editor.getContent())
      })
    }
  }
}
</script>

<style>
.edui-toolbar {
  line-height: 1;
}
</style>
